# Contributor: Leon ROUX <leon.roux@federate.us>
# Maintainer: Leon ROUX <leon.roux@federate.us>
pkgname=cm256cc
pkgver=1.1.0
pkgrel=0
pkgdesc="Fast GF(256) Cauchy MDS Block Erasure Codec library in C++"
url="https://github.com/f4exb/cm256cc"
license="GPL-3.0-only AND MIT AND BSD-3-Clause"
# requires ssse3/neon and does not build anything otherwise
arch="aarch64 x86_64"
makedepends="
	cmake
	samurai
	"
subpackages="$pkgname-dev"
checkdepends="xvfb-run"
source="$pkgname-$pkgver.tar.gz::https://github.com/f4exb/cm256cc/archive/refs/tags/v$pkgver.tar.gz"

build() {
	CFLAGS="$CFLAGS -flto=auto" \
	CXXFLAGS="$CXXFLAGS -flto=auto" \
	cmake -B build -G Ninja \
		-DCMAKE_BUILD_TYPE=Release \
		-DCMAKE_INSTALL_PREFIX=/usr \
		-DENABLE_DISTRIBUTION=ON \
		-DCMAKE_SKIP_INSTALL_RPATH=ON \
		-DBUILD_TOOLS="$(want_check && echo ON || echo OFF)"
	cmake --build build
}

check() {
	./build/cm256_test
	./build/cm256_rx
	./build/cm256_tx
}

package() {
	DESTDIR="$pkgdir" cmake --install build
	# these are just unit tests
	# shellcheck disable=2115
	rm -rfv "$pkgdir"/usr/bin/
}

sha512sums="
2bd02675bb2c1c2b422c626c92bd36a0c0fc7a46a0512475424b1bc781d816137eadc52f33f11e100cdc69a7a595f3153fbed0020d6038916e305a2923700959  cm256cc-1.1.0.tar.gz
"
